package views
{
	import flash.text.*;
	
	import qnx.ui.core.Container;
	import qnx.ui.core.ContainerFlow;
	import qnx.ui.core.SizeUnit;
	import qnx.ui.listClasses.AlternatingCellRenderer;
	import qnx.ui.skins.*;
	import qnx.ui.text.Label;
	
	public class ChannelListRenderer extends AlternatingCellRenderer
	{
		private var chName:Label;
		private var num:Label;
		private var topic:Label;
		
		private var selectedFont:TextFormat;
		private var unselectedFont:TextFormat;
		
		public function ChannelListRenderer()
		{
			this.label.visible = false;
		}
		override protected function init():void
		{
			super.init();
			
			selectedFont =   new TextFormat("Courier New", 18, 0xFFFFFF);
			unselectedFont = new TextFormat("Courier New", 18, 0x0C0E10);
			
			setTextFormatForState(unselectedFont, SkinStates.UP);
			setTextFormatForState(selectedFont, SkinStates.DOWN);
			setTextFormatForState(selectedFont, SkinStates.SELECTED);
			setTextFormatForState(unselectedFont, SkinStates.DISABLED);
			
			chName = new Label();
			chName.width = 220;
			
			num = new Label();
			num.width = 50;
			num.x = 221;
			
			topic = new Label();
			topic.width = 750;
			topic.x = 271;
			

			
			var container:Container = new Container();
			container.flow = ContainerFlow.HORIZONTAL;
			container.size = 100;
			container.sizeUnit = SizeUnit.PERCENT;
			
			container.addChild(chName);
			container.addChild(num);
			container.addChild(topic);
			
			this.addChild(container);
			
		}
		
		override public function set data(data:Object):void
		{
			super.data= data;
			if( data ){
				if(data.hasOwnProperty("name")){
					chName.text = data.name;
				}
				if(data.hasOwnProperty("userCount")){
					num.text = data.userCount;
				}
				if(data.hasOwnProperty("topic")){
					topic.text = data.topic;
				}
			}
		}
		override protected function setLabelState(state:String):void
		{
			var format:TextFormat = getTextFormatForState(state);
			if(format != null){
				if(chName)chName.format = format;
				if(num)num.format = format;
				if(topic)topic.format = format;
			}
		}
	}
}